package com.yunfei.utils.json;

import java.io.*;

/**
 * @program: springclould_ylcaifu_App
 * @description:
 * @author: zhengyunfei
 * @create: 2019-08-09 17:15
 **/
public class JsonUtil {
    /**
     * 读取json文件，返回json串
     * @param fileName
     * @return
     */
    public static String readJsonFile(String fileName) {
        String jsonStr = "";
        try {
            File jsonFile = new File(fileName);
            FileReader fileReader = new FileReader(jsonFile);

            Reader reader = new InputStreamReader(new FileInputStream(jsonFile),"utf-8");
            int ch = 0;
            StringBuffer sb = new StringBuffer();
            while ((ch = reader.read()) != -1) {
                sb.append((char) ch);
            }
            fileReader.close();
            reader.close();
            jsonStr = sb.toString();
            return jsonStr;
        } catch (IOException e) {
            e.printStackTrace();
            return null;
        }
    }
    /**
    * @Description: 获取生成电子合同的参数的json数据
    * @return: java.lang.String
    * @Author: zhengyunfei
    * @Date: 2019/8/9
    * @time:17:21
    */
    public static String getElecHeTongJson(){
        String path = JsonUtil.class.getClassLoader().getResource("json/createElecHeTong.json").getPath();
        String s = JsonUtil.readJsonFile(path);
        return s;
    }
    public static void main(String args[]){
        String path = JsonUtil.class.getClassLoader().getResource("json/createElecHeTong.json").getPath();
        String s = JsonUtil.readJsonFile(path);
        System.out.println(s);
    }
}
